﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.Diagnostics;

namespace SilverSmug
{
    public class SMImage
    {
        public string key { get; set; }
        public string id { get; set; }        
        public string url { get; set; }
        private ImageUrlDownloaded cb;

        public void retrieveURL(ImageUrlDownloaded callback)
        {
            this.cb = callback;            
            String req = SmugAcc.makeRequestURL(SmugAcc.getImageInfoMethod, "SessionID=" + SmugAcc.sessionID,
                                                   "ImageID=" + id, "ImageKey=" + key);
            SmugAcc.sendRequest(req, parseUrls);
        }

        private void parseUrls(XDocument xDoc)
        {
            url = xDoc.Element("rsp").Element("Image").Attribute("TinyURL").Value;
            if(url == null) 
                Debug.WriteLine("no Url returned for: " + id);
            cb();
        }

        public delegate void ImageUrlDownloaded();       

     
    }
}
